Check whether entity instances match a condition

Check whether entity instances match a condition

When using entities in a rulebase, you can check whether entity instances match particular conditions.

What do you want to do?

Count the number of instances of an entity for which a particular attribute is true

Get the highest/most recent value of an entity-level variable for which a particular attribute is true 

Get the lowest/least recent value of an entity-level variable for which a particular attribute is true

Add up numerical values gathered from each instance of an entity for which a particular attribute is true

Count the number of instances of an entity for which a particular attribute is true

To count the number of instances there are of an entity for which a particular entity-level attribute has a particular value, you use the Instance Count If function. The syntax for this function is:

 

For example, the Instance Count If function could be used to determine the number of school students for the claimant:

the number of school students that the claimant has = InstanceCountIf(the claimant's children, the child is a school student)

(For this rule to compile the following entities and relationship must be included in a properties files in the project: an entity 'the claimant' , an entity 'the child' and a one-to-many relationship 'the claimant's children'.)

 

The function returns a value of 1 for the following data: 

 

the child the child is a school student
Rachel false
Michael false
Simon true

 

NOTES:

  1. You can only put one attribute as the 'If' parameter in the function, but that attribute can be proven in a separate rule by any number of other conditions.

  2. The InstanceCountIf() function will return unknown if the relationship supplied to it is unknown, regardless of whether or not any of the relationship's targets are known. It will also return unknown if the attribute being examined is unknown for any of the relationship's targets.

Get the highest/most recent value of an entity-level variable for which a particular attribute is true

To obtain the highest or most recent value of an entity-level variable for all instances of the entity for which a particular entity-level attribute has a particular value, you use the Instance Maximum If function. The syntax for this function is:

 

For example, the Instance Maximum If function could be used to determine the most recent date of employment of a permanent employee by a company:

the most recent date of employment of a permanent employee by the company = InstanceMaximumIf(the company's employees, the employee's date of employment, the employee is a permanent employee)

(For this rule to compile the following entities and relationship must be included in a properties files in the project: an entity 'the company' , an entity 'the employee' and a one-to-many relationship 'the company's employees'.)

 

The function returns a value of 15/05/2006 for the following data: 

 

the employee the employee's date of employment the employee is a permanent employee
David 01/01/2006 true
Shaun 24/08/2006 false
Anita 15/05/2006 true

 

NOTES:

  1. You can only put one attribute as the 'If' parameter in the function, but that attribute can be proven in a separate rule by any number of other conditions.

  2. The InstanceMaximumIf() function will return unknown if the relationship supplied to it is unknown, regardless of whether or not any of the relationship's targets are known. It will also return unknown if the attribute being examined is unknown for any of the relationship's targets.

Get the lowest/least recent value of an entity-level variable for which a particular attribute is true

To obtain the lowest or least recent value of an entity-level variable for all instances of the entity for which a particular entity-level attribute has a particular value, you use the Instance Minimum If function. The syntax for this function is:

 

For example, the Instance Minimum If function could be used to determine the youngest of the claimant's female children:

the youngest of the claimant's female children = InstanceMinimumIf(the claimant's children, the child's age, the child is female)

(For this rule to compile the following entities and relationship must be included in a properties files in the project: an entity 'the claimant' , an entity 'the child' and a one-to-many relationship 'the claimant's children'.)

 

The function returns a value of 4 for the following data: 

 

the child the child's age the child is female
Sam 3 false
Alex 4 true
Shannon 6 false
Paris 8 true

 

NOTES:

  1. You can only put one attribute as the 'If' parameter in the function, but that attribute can be proven in a separate rule by any number of other conditions.

  2. The InstanceMinimumIf() function will return unknown if the relationship supplied to it is unknown, regardless of whether or not any of the relationship's targets are known. It will also return unknown if the attribute being examined is unknown for any of the relationship's targets.

Add up numerical values gathered from each instance of an entity for which a particular attribute is true

To obtain the sum of all instances of an entity-level variable for which it is true of the entity that a specific entity-level boolean attribute is true, you use the Instance Sum If function. The syntax for this function is:

 

For example, the Instance Sum If function could be used to determine the total boarding school fees for the claimant:

the total cost of boarding school fees for the claimant = InstanceSumIf(the claimant's children, the annual school fees for the child, the child attends a boarding school)

(For this rule to compile the following entities and relationship must be included in a properties files in the project: an entity 'the claimant' , an entity 'the child' and a one-to-many relationship 'the claimant's children'.)

 

The function returns a value of $33000 for the following data:

 

the child the annual school fees for the child the child attends a boarding school
Sally $18000 true
James $15000 true
Bob $10000 false

 

NOTES:

  1. You can only put one attribute as the 'If' parameter in the function, but that attribute can be proven in a separate rule by any number of other conditions.

  2. The InstanceSumIf() function will return unknown if the relationship supplied to it is unknown, regardless of whether or not any of the relationship's targets are known. It will also return unknown if the attribute being examined is unknown for any of the relationship's targets.

 

See also: